package com.kd.enums.product;

/**
 * 结构枚举（对应四面叉产品）
 * 数据库字段：structure CHAR(1) COMMENT 'N-无 A|B(仅四面叉)'
 */
public enum StructureEnum {
    NONE("N", "无"),
    TYPE_A("A", "A型结构"),
    TYPE_B("B", "B型结构");

    private final String code;
    private final String desc;

    StructureEnum(String code, String desc) {
        this.code  = code;
        this.desc  = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static StructureEnum getByCode(String code) {
        if (code == null) return null;

        for (StructureEnum value : values()) {
            if (value.code.equals(code))  {
                return value;
            }
        }
        throw new IllegalArgumentException("无效的结构代码: " + code);
    }

    // 四面叉专用校验
    public static boolean isValidForSideFork(String code, int sidefork) {
        if (sidefork == 1) { // 四面叉
            return code == null ||
                    code.equals(NONE.code)  ||
                    code.equals(TYPE_A.code)  ||
                    code.equals(TYPE_B.code);
        }
        return code == null || code.equals(NONE.code);  // 非四面叉只能为null或N
    }
}